#pragma once
#include "Image.h"

void Image::LoadSurface(string FileName)
{
	SDL_Surface *RawLoad = NULL;
	SDL_Surface *OptLoad = NULL;

	RawLoad = IMG_Load(FileName.c_str());
	if(RawLoad != NULL) OptLoad = SDL_ConvertSurface(RawLoad, RawLoad->format, RawLoad->flags || SDL_SRCCOLORKEY);
	Surface = OptLoad;
}

void Image::SetColorKey(Uint8 R, Uint8 G, Uint8 B)
{
	if(Surface != NULL)
	{
		Uint32 ColorKey = SDL_MapRGB(Surface->format, R, G, B);
		SDL_SetColorKey(Surface, SDL_SRCCOLORKEY, ColorKey);
	}
}

Corner Image::GetCornerPos()
{
	PixPtr CornerPos(0, 0);
	Corner RetVal;

	RetVal.UPPER_LEFT.Set(Box.x, Box.y);
	RetVal.UPPER_RIGHT.Set(Box.x + Box.w, Box.y);
	RetVal.BOTTOM_LEFT.Set(Box.x, Box.y + Box.h);
	RetVal.BOTTOM_RIGHT.Set(Box.x + Box.w, Box.y + Box.h);

	return RetVal;
}

IntPtr2D Image::GetSurfSize()
{
	PixPtr RetVal(Surface->w, Surface->h);
	return RetVal;
	SDL_UnlockSurface(Surface);
}

void Image::Draw(int X, int Y)
{
	Box.x = X;
	Box.y = Y;
	SDL_BlitSurface(Surface, NULL, E_VP, &Box);	
}

void Image::Draw(PixPtr Pos)
{
	Box.x = Pos.X;
	Box.y = Pos.Y;
	SDL_BlitSurface(Surface, NULL, E_VP, &Box);
}

Image::Image()
{
	Surface = NULL;
}

Image::Image(string FileName)
{
	LoadSurface(FileName);
}